package com.smedi.ismedi.inmail.core.port.adapter.restful;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smedi.ismedi.inmail.api.dto.request.*;
import com.smedi.ismedi.inmail.api.dto.response.*;
import com.smedi.ismedi.inmail.api.feign.RemoteOverviewFeignApi;
import com.smedi.ismedi.inmail.core.application.command.*;
import com.smedi.ismedi.inmail.core.application.query.OverviewQueryService;
import com.smedi.ismedi.inmail.core.application.query.vo.*;
import com.smedi.ismedi.inmail.core.application.service.OverviewApplicationService;
import com.smedi.ismedi.inmail.core.port.adapter.convert.AdapterConverter;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 通知公告Controller
 *
 * @author jiangqinxuan
 * @date 2021/07/26
 */
@AllArgsConstructor
@RestController
public class OverviewController implements RemoteOverviewFeignApi {
    private final OverviewQueryService overviewQueryService;
    private final OverviewApplicationService overviewApplicationService;
    private final AdapterConverter adapterConverter;

    @Override
    public ResponseData<ProjectOverviewPaginationData> getProjectOverviewPage(ProjectOverviewPageRequest projectOverviewPageRequest) {
        ProjectOverviewPageCommand projectOverviewPageCommand = adapterConverter.projectOverviewPageRequestToProjectOverviewPageCommand(projectOverviewPageRequest);
        ProjectOverviewPageVo projectOverviewPage = overviewQueryService.getProjectOverviewPage(projectOverviewPageCommand);
        ProjectOverviewPaginationData projectOverviewPaginationData = adapterConverter.projectOverviewPageVoToProjectOverviewPaginationData(projectOverviewPage);
        return new ResponseData<>().success(projectOverviewPaginationData);
    }

    @Override
    public ResponseData<String> exportProjectOverview(ProjectOverviewListRequest projectOverviewListRequest) {
        ProjectOverviewListCommand projectOverviewListCommand = adapterConverter.projectOverviewListRequestToProjectOverviewListCommand(projectOverviewListRequest);
        List<ProjectOverviewVo> projectOverviews = overviewQueryService.getProjectOverviewList(projectOverviewListCommand);
        return new ResponseData<>().success(overviewApplicationService.exportProjectOverview(projectOverviews));
    }

    @Override
    public ResponseData<PaginationData<SafetyCheckProjectOverviewResponse>> getSafetyCheckProjectOverviewPage(SafetyCheckProjectOverviewPageRequest safetyCheckProjectOverviewPageRequest) {
        SafetyCheckProjectOverviewPageCommand safetyCheckProjectOverviewPageCommand = adapterConverter.safetyCheckProjectOverviewPageRequestToSafetyCheckProjectOverviewPageCommand(safetyCheckProjectOverviewPageRequest);
        Page<SafetyCheckProjectOverviewVo> safetyCheckProjectOverviewPage = overviewQueryService.getSafetyCheckProjectOverviewPage(safetyCheckProjectOverviewPageCommand);
        PaginationData<SafetyCheckProjectOverviewResponse> safetyCheckProjectOverviewResponsePaginationData = adapterConverter.safetyCheckProjectOverviewPageToSafetyCheckProjectOverviewResponsePaginationData(safetyCheckProjectOverviewPage);
        return new ResponseData<>().success(safetyCheckProjectOverviewResponsePaginationData);
    }

    @Override
    public ResponseData<String> exportSafetyCheckProjectOverview(SafetyCheckProjectOverviewListRequest safetyCheckProjectOverviewListRequest) {
        SafetyCheckProjectOverviewListCommand safetyCheckProjectOverviewListCommand = adapterConverter.safetyCheckProjectOverviewListRequestToSafetyCheckProjectOverviewListCommand(safetyCheckProjectOverviewListRequest);
        List<SafetyCheckProjectOverviewVo> safetyCheckProjectOverviewList = overviewQueryService.getSafetyCheckProjectOverviewList(safetyCheckProjectOverviewListCommand);
        return new ResponseData<>().success(overviewApplicationService.exportSafetyCheckProjectOverview(safetyCheckProjectOverviewList));
    }

    @Override
    public ResponseData<SafetyCheckOrgOverviewPaginationData> getSafetyCheckOrganizationOverviewPage(SafetyCheckOrganizationOverviewPageRequest safetyCheckOrganizationOverviewPageRequest) {
        SafetyCheckOrganizationOverviewPageCommand safetyCheckOrganizationOverviewPageCommand = adapterConverter.safetyCheckOverviewPageRequestToSafetyCheckOverviewPageCommand(safetyCheckOrganizationOverviewPageRequest);
        SafetyCheckOrgOverviewPageVo safetyCheckOrgOverviewPageVo = overviewQueryService.getSafetyCheckOrganizationOverviewPage(safetyCheckOrganizationOverviewPageCommand);
        SafetyCheckOrgOverviewPaginationData safetyCheckOrgOverviewPaginationData = adapterConverter.safetyCheckOrgOverviewPageVoToSafetyCheckOrgOverviewPaginationData(safetyCheckOrgOverviewPageVo);
        return new ResponseData<>().success(safetyCheckOrgOverviewPaginationData);
    }

    @Override
    public ResponseData<String> exportSafetyCheckOrganizationOverview(SafetyCheckOrganizationOverviewListRequest safetyCheckOrganizationOverviewListRequest) {
        SafetyCheckOrganizationOverviewListCommand safetyCheckOrganizationOverviewListCommand = adapterConverter.safetyCheckOverviewListRequestToSafetyCheckOverviewListCommand(safetyCheckOrganizationOverviewListRequest);
        List<SafetyCheckOrganizationOverviewVo> safetyCheckOverviews = overviewQueryService.getSafetyCheckOrganizationOverviewList(safetyCheckOrganizationOverviewListCommand);
        return new ResponseData<>().success(overviewApplicationService.exportSafetyCheckOrganizationOverview(safetyCheckOverviews));
    }

    @Override
    public ResponseData<PaginationData<AttendanceOverviewResponse>> getAttendanceOverviewPage(AttendanceOverviewPageRequest attendanceOverviewPageRequest) {
        AttendanceOverviewPageCommand attendanceOverviewPageCommand = adapterConverter.attendanceOverviewPageRequestToAttendanceOverviewPageCommand(attendanceOverviewPageRequest);
        Page<AttendanceOverviewVo> attendanceOverviewPage = overviewQueryService.getAttendanceOverviewPage(attendanceOverviewPageCommand);
        PaginationData<AttendanceOverviewResponse> attendanceOverviewResponsePaginationData = adapterConverter.attendanceOverviewPageToAttendanceOverviewResponsePaginationData(attendanceOverviewPage);
        return new ResponseData<>().success(attendanceOverviewResponsePaginationData);
    }

    @Override
    public ResponseData<PaginationData<ProjectPersonOverViewResponse>> projectLevelOverviewPage(ProjectOverviewPageRequest projectOverviewPageRequest) {
        ProjectOverviewPageCommand projectOverviewPageCommand = adapterConverter.projectOverviewPageRequestToProjectOverviewPageCommand(projectOverviewPageRequest);
        Page<ProjectPersonOverViewVo>  projectOverviewPage = overviewQueryService.getProjectLevelOverViewPage(projectOverviewPageCommand);
        PaginationData<ProjectPersonOverViewResponse> projectPersonOverViewResponsePaginationData = adapterConverter.pageToPaginationData(projectOverviewPage);
        return new ResponseData<>().success(projectPersonOverViewResponsePaginationData);
    }

    @Override
    public ResponseData<PaginationData<ProjectPostOverViewResponse>> projectPostOverviewPage(ProjectOverviewPageRequest projectOverviewPageRequest) {
        ProjectOverviewPageCommand projectOverviewPageCommand = adapterConverter.projectOverviewPageRequestToProjectOverviewPageCommand(projectOverviewPageRequest);
        Page<ProjectPostOverViewVo>  projectOverviewPage = overviewQueryService.getProjectPostOverViewPage(projectOverviewPageCommand);
        PaginationData<ProjectPostOverViewResponse> projectPersonOverViewResponsePaginationData = adapterConverter.postPageToPaginationData(projectOverviewPage);
        return new ResponseData<>().success(projectPersonOverViewResponsePaginationData);
    }

    @Override
    public ResponseData<List<ProjectJobPersonResponse>> projectJobPersonList(Long projectId, String projectJob) {
        List<ProjectJobPersonVo> projectJobPersonVos = overviewQueryService.projectJobPersonList(projectId, projectJob);
        return new ResponseData<>().success(adapterConverter.projectJobPersonVoToProjectJobPersonResponse(projectJobPersonVos));
    }

    @Override
    public ResponseData<ProjectPostPersonOverViewResponse> projectPostPersonList(Long projectId) {
        ProjectPostPersonOverViewVo projectJobPersonVo = overviewQueryService.projectPostPerson(projectId);
        return new ResponseData<>().success(adapterConverter.projectPostPersonVoToProjectPostPersonResponse(projectJobPersonVo));
    }

    @Override
    public ResponseData<String> exportAttendanceOverview(AttendanceOverviewListRequest attendanceOverviewListRequest) {
        AttendanceOverviewListCommand attendanceOverviewListCommand = adapterConverter.attendanceOverviewListRequestToAttendanceOverviewListCommand(attendanceOverviewListRequest);
        List<AttendanceOverviewVo> attendanceOverviews = overviewQueryService.getAttendanceOverviewList(attendanceOverviewListCommand);
        return new ResponseData<>().success(overviewApplicationService.exportAttendanceOverview(attendanceOverviews));
    }

    @Override
    public ResponseData<VideoMonitorOrgOverviewPaginationData> getVideoMonitorOrganizationOverviewPage(VideoMonitorOrganizationOverviewPageRequest videoMonitorOrganizationOverviewPageRequest) {
        VideoMonitorOrganizationOverviewPageCommand videoMonitorOrganizationOverviewPageCommand = adapterConverter.videoMonitorOrganizationOverviewPageRequestToVideoMonitorOrganizationOverviewPageCommand(videoMonitorOrganizationOverviewPageRequest);
        VideoMonitorOrgOverviewPageVo videoMonitorOrgOverviewPageVo = overviewQueryService.getVideoMonitorOrganizationOverviewPage(videoMonitorOrganizationOverviewPageCommand);
        VideoMonitorOrgOverviewPaginationData videoMonitorOrgOverviewPaginationData = adapterConverter.videoMonitorOrgOverviewPageVoToVideoMonitorOrgOverviewPaginationData(videoMonitorOrgOverviewPageVo);
        return new ResponseData<>().success(videoMonitorOrgOverviewPaginationData);
    }

    @Override
    public ResponseData<String> exportVideoMonitorOrganizationOverview(VideoMonitorOrganizationOverviewListRequest videoMonitorOrganizationOverviewListRequest) {
        VideoMonitorOrganizationOverviewListCommand videoMonitorOrganizationOverviewListCommand = adapterConverter.videoMonitorOrganizationOverviewListRequestToVideoMonitorOrganizationOverviewListCommand(videoMonitorOrganizationOverviewListRequest);
        List<VideoMonitorOrganizationOverviewVo> videoMonitorOrganizationOverviews = overviewQueryService.getVideoMonitorOrganizationOverviewList(videoMonitorOrganizationOverviewListCommand);
        return new ResponseData<>().success(overviewApplicationService.exportVideoMonitorOrganizationOverview(videoMonitorOrganizationOverviews));
    }

    @Override
    public ResponseData<PaginationData<VideoMonitorProjectOverviewResponse>> getVideoMonitorProjectOverviewPage(VideoMonitorProjectOverviewPageRequest videoMonitorProjectOverviewPageRequest) {
        VideoMonitorProjectOverviewPageCommand videoMonitorProjectOverviewPageCommand = adapterConverter.videoMonitorProjectOverviewPageRequestToVideoMonitorProjectOverviewPageCommand(videoMonitorProjectOverviewPageRequest);
        Page<VideoMonitorProjectOverviewVo> videoMonitorProjectOverviewPage = overviewQueryService.getVideoMonitorProjectOverviewPage(videoMonitorProjectOverviewPageCommand);
        PaginationData<VideoMonitorProjectOverviewResponse> videoMonitorProjectOverviewResponsePaginationData = adapterConverter.videoMonitorProjectOverviewPageToVideoMonitorProjectOverviewResponsePaginationData(videoMonitorProjectOverviewPage);
        return new ResponseData<>().success(videoMonitorProjectOverviewResponsePaginationData);
    }

    @Override
    public ResponseData<String> exportVideoMonitorProjectOverview(VideoMonitorProjectOverviewListRequest videoMonitorProjectOverviewListRequest) {
        VideoMonitorProjectOverviewListCommand videoMonitorProjectOverviewListCommand = adapterConverter.videoMonitorProjectOverviewListRequestToVideoMonitorProjectOverviewListCommand(videoMonitorProjectOverviewListRequest);
        List<VideoMonitorProjectOverviewVo> videoMonitorProjectOverviews = overviewQueryService.getVideoMonitorProjectOverviewList(videoMonitorProjectOverviewListCommand);
        return new ResponseData<>().success(overviewApplicationService.exportVideoMonitorProjectOverview(videoMonitorProjectOverviews));
    }

    @Override
    public ResponseData<PaginationData<DingAttendanceOverViewResponse>> getDingAttendancePaginationDataResponseData(DingAttendanceOverViewPageRequest dingAttendanceOverViewPageRequest) {
        DingAttendanceOverViewPageCommand dingAttendanceOverViewPageCommand = adapterConverter.dingAttendanceOverViewPageRequestToDingAttendanceOverViewPageCommand(dingAttendanceOverViewPageRequest);
        Page<DingAttendanceOverViewVo> page = overviewQueryService.getDingAttendanceOverViewPage(dingAttendanceOverViewPageCommand);
        PaginationData<DingAttendanceOverViewResponse> pageData = adapterConverter.dingAttendanceOverViewVoPageToDingAttendanceOverViewResponsePaginationData(page);
        return new ResponseData<>().success(pageData);
    }

    @Override
    public ResponseData<PaginationData<DingAttendanceProjectOverViewResponse>> getDingAttendanceProjectPaginationDataResponseData(DingAttendanceProjectOverViewPageRequest dingAttendanceProjectOverViewPageRequest) {
        DingAttendanceProjectOverViewPageCommand command = adapterConverter.dingAttendanceProjectOverViewPageRequestToDingAttendanceProjectOverViewPageCommand(dingAttendanceProjectOverViewPageRequest);
        Page<DingAttendanceProjectOverViewVo> page = overviewQueryService.getDingAttendanceProjectOverViewPage(command);
        PaginationData<DingAttendanceProjectOverViewResponse> paginationData = adapterConverter.dingAttendanceProjectOverViewVoPageToDingAttendanceProjectOverViewResponsePaginationData(page);
        return new ResponseData<>().success(paginationData);
    }

    @Override
    public ResponseData<DingDingAttendanceProjectResponse> getProjectDetail(DingDingProjectRequest dingDingProjectRequest) {
        DingDingAttendanceProjectVo vo = overviewQueryService.getDingDingAttendanceProjectVo(dingDingProjectRequest);
        DingDingAttendanceProjectResponse response = adapterConverter.dingDingAttendanceProjectVoToDingDingAttendanceProjectResponse(vo);
        return new ResponseData<>().success(response);
    }

    @Override
    public ResponseData<String> exportOrgAttendance(DingAttendanceOrgExportRequest request) {
        DingAttendanceOverViewPageCommand command = adapterConverter.dingAttendanceOrgExportToDingAttendanceOverViewPageCommand(request);
        List<DingAttendanceOverViewVo> voList = overviewQueryService.getDingAttendanceOrgList(command);
        return new ResponseData<>().success(overviewApplicationService.exportDingAttendanceList(voList));
    }

    @Override
    public ResponseData<String> exportProjectAttendance(DingAttendanceProjectExportRequest request) {
        DingAttendanceProjectOverViewPageCommand command = adapterConverter.dingAttendanceProjectExportRequestToDingAttendanceProjectOverViewPageCommand(request);
        List<DingAttendanceProjectOverViewVo> voList = overviewQueryService.getDingAttendanceProjectList(command);
        return new ResponseData<>().success(overviewApplicationService.exportDingAttendanceProjectList(voList));
    }


    @Override
    public ResponseData<PaginationData<DingDingAttendanceProjectDetailResponse>> projectDetailPage(DingProjectDetailPageRequest request) {
        DingProjectDetailPageCommand command = adapterConverter.dingProjectDetailRequestToDingProjectDetailPageCommand(request);
        Page<DingAttendanceProjectOverViewVo> page = overviewQueryService.getDingAttendanceProjectDetailOverViewPage(command);
        PaginationData<DingDingAttendanceProjectDetailResponse> paginationData = adapterConverter.dingAttendanceProjectOverViewVoPageToDingAttendanceProjectDetailPageResponsePaginationData(page);
        return new ResponseData<>().success(paginationData);
    }

    @Override
    public ResponseData<PaginationData<DingDingAttendancePeopleDetailResponse>> peopleDetailPage(DingProjectDetailPageRequest request) {
        DingProjectDetailPageCommand command = adapterConverter.dingProjectDetailRequestToDingProjectDetailPageCommand(request);
        Page<DingPeopleDetailOverViewVo> page = overviewQueryService.getDingAttendancePeopleDetailOverViewPage(command);
        PaginationData<DingDingAttendancePeopleDetailResponse> paginationData = adapterConverter.dingAttendancePeopleOverViewVoPageToDingAttendancePeopleDetailPageResponsePaginationData(page);
        return new ResponseData<>().success(paginationData);
    }

    @Override
    public ResponseData<Boolean> updateDingTalkData() {
        overviewApplicationService.updateDingTalkData();
        return new ResponseData<>().success(true);
    }

    @Override
    public ResponseData<Boolean> updateDingTalkPerson() {
        overviewApplicationService.updateDingTalkPerson();
        return new ResponseData<>().success(true);
    }

    @Override
    public ResponseData<Boolean> peopleExist(Long personId) {
        return new ResponseData<>().success( overviewApplicationService.personExist(personId));
    }

    @Override
    public ResponseData<List<String>> peopleByProjectId(Long projectId) {
        return new ResponseData<>().success( overviewApplicationService.peopleByProjectId(projectId));
    }
}
